﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MvvmFoundation.Wpf;
using System.Windows.Input;
using System.Windows.Controls;
using Revis.VClinicNet.UI.External.Client.Service;

namespace Revis.VClinicNet.UI.External.Client.ViewModel
{
    public interface IWorkspaceCommand
    {
        string DisplayName { get; set; }
        ICommand Command { get; }
        IWorkspaceControl Create(IPatientService ips);
    }

    public class WorkspaceCommandViewModel<TView, TViewModel> : ObservableObject, IWorkspaceCommand
        where TView : UserControl, new()
        where TViewModel : WorkspaceControlViewModelBase<TView>, new()
    {
        public string DisplayName { get; set; }
        public ICommand Command { get; private set; }

        public WorkspaceCommandViewModel(string displayName, Action<IWorkspaceCommand> action)
        {
            if (action == null) {
                throw new ArgumentNullException("command");
            }
            DisplayName = displayName;
            Command = new RelayCommand(() => {
                action(this);
            });
        }

        public IWorkspaceControl Create(IPatientService ips)
        {
            TViewModel viewModel = new TViewModel();
            viewModel.Initialize(DisplayName, ips);
            return viewModel;
        }
    }
}
